package org.xbdframework.sample.sso.authserver.confg.redis;


/**
 * @className: RedisConfig
 * @Auther: wangweichao
 * @Date: 2022/2/22 11:01
 * @Description: Security Oauth Redis整合 token信息存储到redis
 */
//@Configuration
public class OauthRedisConfig {

    private static final String SCOPE = "scope";

    private static final String USERNAME = "username";

    private static final String OS_TYPE = "osType";

    private static final String DEVICE_TYPE = "device_type";

    /**
     * 开水壶app用户标识
     */
    private static final String DEVICE_TYPE_KSH_APP = "ksh_app";

    /**
     * 小壶优选设备类型标识
     */
    private static final String DEVICE_TYPE_ALLIANCE_PROGRAM = "alliance_program";

    /**
     * 快乐组局设备类型标识
     */
    private static final String DEVICE_TYPE_HAPPY_GROUP_PROGRAM = "happy_group_program";

    /**
     * 小壶优选bd项目web类型标识
     */
    private static final String DEVICE_TYPE_ALLIANCE_BD_WEB = "alliance_bd_web";

    /**
     * 小壶优选bd项目H5类型标识
     */
    private static final String DEVICE_TYPE_ALLIANCE_BD_H5 = "alliance_bd_h5";

    //@Autowired
    //private RedisConnectionFactory redisConnectionFactory;

    /**
     * @return org.springframework.security.oauth2.provider.token.TokenStore
     * @Author: Mr.Liu
     * @Description: token实现方式，采用redis存储
     * @Date 2023/8/3 9:37
     **/
    /*@Bean
    public TokenStore redisTokenStore(){
        RedisTokenStore redisTokenStore = new RedisTokenStore(redisConnectionFactory);
        // 设置redis token存储中的前缀
        redisTokenStore.setPrefix("auth-token:");
        //设置token key生成策略
        redisTokenStore.setAuthenticationKeyGenerator(new DefaultAuthenticationKeyGenerator() {
            @Override
            public String extractKey(OAuth2Authentication authentication) {
                Map<String, String> values = new LinkedHashMap<String, String>();
                OAuth2Request authorizationRequest = authentication.getOAuth2Request();
                if (!authentication.isClientOnly()) {
                    values.put(USERNAME, authentication.getName());
                }
                if (authorizationRequest.getScope() != null) {
                    values.put(SCOPE, OAuth2Utils.formatParameterList(new TreeSet<String>(authorizationRequest.getScope())));
                }
                String osType = authorizationRequest.getRequestParameters().get(OS_TYPE);
                String deviceType = DEVICE_TYPE_KSH_APP;
                *//*if (LoginOsTypeEnum.SHOP_ALLIANCE_WECHAT_PROGRAM.getOsType().equalsIgnoreCase(osType)) {
                    deviceType = DEVICE_TYPE_ALLIANCE_PROGRAM;
                } else if (LoginOsTypeEnum.HAPPY_GROUP_WECHAT_PROGRAM.getOsType().equalsIgnoreCase(osType)) {
                    deviceType = DEVICE_TYPE_HAPPY_GROUP_PROGRAM;
                }*//*
                //不同的端不同的类别
                values.put(DEVICE_TYPE, deviceType);
                // 如果是多租户系统，这里要区分租户ID 条件
                return generateKey(values);
            }
        });
        return redisTokenStore;
    }*/
}
